/*
 * @Author: ygnnli 1585923072@qq.com
 * @Date: 2024-08-20 21:05:37
 * @LastEditors: ygnnli 1585923072@qq.com
 * @LastEditTime: 2024-08-20 22:34:04
 * @FilePath: /bitrpc/source/test/test4/subscribe_client.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "../../client/rpc_client.hpp"

void callback(const std::string &key,const std::string &msg)
{
    ILOG("%s 主题收到推送过来的消息: %s",key.c_str(),msg.c_str());
}


int main()
{
    //1.实例化客户端对象
    auto client = std::make_shared<bitrpc::client::TopicClient>("127.0.0.1",7070);
    //2.创建主题
    bool ret = client->create("hello");
    if(ret == false)
    {
        ELOG("创建主题失败!");
    }
    ELOG("创建主题成功！");
    //3.订阅主题
    ret = client->subscribe("hello",callback);
    //4.等待-->退出
    std::this_thread::sleep_for(std::chrono::seconds(20));
    client->shutdown();

    return 0;
}